package se.webbzon.boltzmann.effect;

import se.webbzon.boltzmann.game.object.camera.GameCamera;
import se.webbzon.oschi01.worldarea.WorldArea;
import se.webbzon.oschi01.worldobject.WorldObject;

public abstract class GameCameraEffect extends WorldObject implements Effect {
	
	// The game camera associated with this effect
	private final GameCamera camera;

	// The startup duration of the effect
	private final int duration;

	// The remaining duration of the effect
	private int remaining;

	/*============================================================
	Constructors
	============================================================*/

	public GameCameraEffect(GameCamera camera, int duration) {
		super(WorldObject.onStep);
		this.camera = camera;
		this.duration = duration;
		remaining = duration;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** This method is invoked when the camera effect begins. **/
	public abstract void onEffectBegin(WorldArea world);
	
	/** This method is invoked during each camera effect step. **/
	public abstract void onEffectStep(WorldArea world);
	
	/** This method is invoked when the camera effect ends. **/
	public abstract void onEffectEnd(WorldArea world);
	
	/** Returns the camera associated with this camera effect. **/
	public GameCamera getCamera() {
		return camera;
	}
	
	/** Returns the remaining duration of the effect. **/
	public int getDuration() {
		return remaining;
	}
	
	/** Returns the startup duration of the effect. **/
	public int getStartupDuration() {
		return duration;
	}
	
	@Override public final void launch(WorldArea world) {
		world.createInstance(this);
		onEffectBegin(world);
	}

	@Override public final void terminate(WorldArea world) {
		onEffectEnd(world);
		world.destroyInstance(this);
	}
	
	@Override public final void onStep(WorldArea world) {
		if (remaining == 0)
			terminate(world);
		else if (remaining > 0) {
			onEffectStep(world);
			remaining--;
		}
			
	}

}
